package com.example.hrsystem.data.source;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.example.hrsystem.model.DailyAttendanceRecord;

import java.util.Date;
import java.util.List;

/**
 * 日常考勤记录数据访问对象
 * 提供对daily_attendance_records表的操作方法
 */
@Dao
public interface DailyAttendanceDao {

    /**
     * 插入一条打卡记录
     */
    @Insert
    void insert(DailyAttendanceRecord record);

    /**
     * 更新打卡记录
     */
    @Update
    void update(DailyAttendanceRecord record);

    /**
     * 删除打卡记录
     */
    @Delete
    void delete(DailyAttendanceRecord record);

    /**
     * 根据ID删除打卡记录
     */
    @Query("DELETE FROM daily_attendance_records WHERE id = :id")
    void deleteById(int id);

    /**
     * 查询所有打卡记录
     */
    @Query("SELECT * FROM daily_attendance_records ORDER BY date DESC")
    LiveData<List<DailyAttendanceRecord>> getAllAttendanceRecords();

    /**
     * 根据员工ID查询打卡记录
     */
    @Query("SELECT * FROM daily_attendance_records WHERE employeeId = :employeeId ORDER BY date DESC")
    LiveData<List<DailyAttendanceRecord>> getAttendanceRecordsByEmployeeId(String employeeId);

    /**
     * 根据日期查询打卡记录
     */
    @Query("SELECT * FROM daily_attendance_records WHERE date = :date AND employeeId = :employeeId")
    LiveData<DailyAttendanceRecord> getAttendanceRecordByDate(Date date, String employeeId);

    /**
     * 根据日期查询打卡记录(同步)
     */
    @Query("SELECT * FROM daily_attendance_records WHERE date = :date AND employeeId = :employeeId")
    DailyAttendanceRecord getDailyAttendanceRecordByDate(Date date, String employeeId);

    /**
     * 查询指定日期范围内的打卡记录
     */
    @Query("SELECT * FROM daily_attendance_records WHERE date BETWEEN :startDate AND :endDate AND employeeId = :employeeId ORDER BY date DESC")
    LiveData<List<DailyAttendanceRecord>> getAttendanceRecordsByDateRange(String employeeId, Date startDate, Date endDate);

    /**
     * 查询指定日期范围内的打卡记录(同步)
     */
    @Query("SELECT * FROM daily_attendance_records WHERE date BETWEEN :startDate AND :endDate AND employeeId = :employeeId ORDER BY date DESC")
    List<DailyAttendanceRecord> getDailyAttendanceRecordsByDateRangeSync(String employeeId, Date startDate, Date endDate);
}